package com.jy.rhin.facade.infra.controller.notification;

import com.jy.framework.base.entity.Page;
import com.jy.framework.base.entity.Result;
import com.jy.rhin.application.infra.NotificationApplicationService;
import com.jy.rhin.infra.repo.notfication.publish.query.PublishMessageQueryHandler;
import com.jy.rhin.sdk.dto.notification.SubscriberShortDto;
import com.jy.rhin.sdk.dto.notification.req.FailPublishMessageReqDto;
import com.jy.rhin.sdk.dto.notification.req.IdDto;
import com.jy.rhin.sdk.dto.notification.req.MessageIdReqDto;
import com.jy.rhin.sdk.dto.notification.req.PublishMessagePageReqDto;
import com.jy.rhin.sdk.dto.notification.resp.PublishMessageDetailDto;
import com.jy.rhin.sdk.dto.notification.resp.PublishMessageDto;
import com.jy.rhin.sdk.dto.notification.resp.PublishMessagePageDto;
import com.jy.rhin.sdk.feign.client.PublishMessageFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author dhl
 * @date 2022/6/30
 * @Description
 */
@RestController
@RequestMapping("/infra/notification/publishMessage")
@Api(tags = "事件总线api", value = "通知消息管理api")
@Slf4j
public class PublishMessageController implements PublishMessageFeign {

    @Resource
    private PublishMessageQueryHandler publishMessageQueryHandler;
    @Resource
    private NotificationApplicationService notificationApplicationService;

    @Override
    @ApiOperation("通知消息管理api-通知消息分页查询")
    @GetMapping("/queryPublishMessagePage")
    public Result<Page<PublishMessagePageDto>> queryPublishMessagePage(PublishMessagePageReqDto req) {
        return Result.success(publishMessageQueryHandler.queryPublishMessagePage(req));
    }

    @Override
    @ApiOperation("通知消息管理api-通知消息详情查询")
    @GetMapping("/queryPublishMessageDetail")
    public Result<PublishMessageDetailDto> queryPublishMessageDetail(IdDto req) {
        return Result.success(notificationApplicationService.queryPublishMessageDetail(req));
    }

    @Override
    @ApiOperation("通知消息管理api-获取发送失败的消息列表")
    @GetMapping("/querySendFailPublishMessageList")
    public Result<List<PublishMessageDto>> querySendFailPublishMessageList(FailPublishMessageReqDto req) {
        return Result.success(publishMessageQueryHandler.querySendFailPublishMessageList(req));
    }

    @Override
    @ApiOperation("通知消息管理api-分页获取发送失败的消息列表")
    @GetMapping("/querySendFailPublishMessagePage")
    public Result<Page<PublishMessageDto>> querySendFailPublishMessagePage(FailPublishMessageReqDto req) {
        return Result.success(publishMessageQueryHandler.querySendFailPublishMessagePage(req));
    }

    @Override
    @ApiOperation("通知消息管理api-根据消息id获取消息订阅者列表")
    @GetMapping("/queryMessageSubscriberListByMsgId")
    public Result<List<SubscriberShortDto>> queryMessageSubscriberListByMsgId(MessageIdReqDto dto) {
        return Result.success(publishMessageQueryHandler.queryMessageSubscriberListByMsgId(dto.getMsgId()));
    }
}
